package com.yzc.android.ui.adapter;

import android.support.annotation.LayoutRes;
import android.view.View;

import java.util.List;

import com.marshalchen.ultimaterecyclerview.UltimateRecyclerviewViewHolder;
import com.yzc.android.R;
import com.yzc.android.network.response.SectionDataResponse;
import com.yzc.android.ui.viewholder.HeaderViewHolder;
import com.yzc.android.ui.viewholder.ItemViewHolder;
import com.yzc.android.ui.viewholder.KDBaseViewHolder;
import com.yzc.android.ui.viewholder.SectionViewHolder;

/**
 * Created by yzc on 16/4/21.
 */
public class RecyclerViewSectionAdapter extends KDRecyclerViewBaseAdapter<SectionDataResponse, UltimateRecyclerviewViewHolder>
{

    public RecyclerViewSectionAdapter(final List<SectionDataResponse> list) {
        super(list);
    }

    @Override
    protected @LayoutRes int getItemLayoutResId() {
        return R.layout.layout_recycler_view_item;
    }

    @Override
    protected @LayoutRes int getSectionLayoutResId() {
        return R.layout.layout_recycler_view_sticky_header;
    }

    @Override
    public long generateHeaderId(final int position) {
        if (position < 0 || position >= getAdapterItemCount()) return -1;
        SectionDataResponse data = getItem(position);
        return data.mSectionBean.sectionId;
    }

    @Override
    protected UltimateRecyclerviewViewHolder createCustomViewHolder(final View view, final int viewTypes) {
        switch (viewTypes)
        {
            case VIEW_TYPES.SECTION:
            {
                return new SectionViewHolder(view);
            }
            case VIEW_TYPES.NORMAL:
            {
                return new ItemViewHolder(view);
            }
            case VIEW_TYPES.HEADER:
            {
                return new HeaderViewHolder(view);
            }
            case VIEW_TYPES.FOOTER:
            {
                return new UltimateRecyclerviewViewHolder(view);
            }
            default:
                break;
        }
        return null;
    }

    @SuppressWarnings("unchecked")
    @Override
    protected void bindCustomViewHolder(final KDBaseViewHolder holder, final int position, final int viewTypes) {
        switch (viewTypes)
        {
            case VIEW_TYPES.SECTION:
            {
                SectionDataResponse model = getItem(position);
                holder.showData(position, model);
            }
            break;
            case VIEW_TYPES.NORMAL:
            {
                SectionDataResponse model = getItem(position);
                holder.showData(position, model);
            }
            break;
            case VIEW_TYPES.HEADER:
            {
                holder.showData(position, null);
            }
            break;
            case VIEW_TYPES.FOOTER:
            {
                break;
            }
            default:
                break;
        }
    }
}
